package com.itheima.health.service.impl;

import com.itheima.health.dao.OrderSettingDao;
import com.itheima.health.pojo.OrderSetting;
import com.itheima.health.service.OrderSettingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.*;

/**
 * @author zhangmeng
 * @description
 * @date 2019/9/18
 **/
@Service
@Slf4j
@Transactional
public class OrderSettingServiceImpl implements OrderSettingService {
    @Autowired
    private OrderSettingDao orderSettingDao;

    @Override
    public void insert(List<OrderSetting> orderSettings) {
        for (OrderSetting orderSetting : orderSettings) {
            if (orderSettingDao.findOrderDate(orderSetting.getOrderDate()) > 0) {
                orderSettingDao.updateNumberOrderDate(orderSetting);
            }
            orderSettingDao.addordersetting(orderSetting);

        }
    }

    @Override
    public List<OrderSetting> getOrderSettingByMonth(String year,String month) {
        String begin = year + "-" + month +"-01";
        String end =year + "-" + month + "-31";
        return orderSettingDao.getOrderSettingByMonth(begin,end);
    }

    @Override
    public void updateNumberOrderDate(OrderSetting orderSetting) {
        Long orderDate = orderSettingDao.findOrderDate(orderSetting.getOrderDate());
        if (orderDate > 0){
            orderSettingDao.updateNumberOrderDate(orderSetting);
        }
        orderSettingDao.addordersetting(orderSetting);
    }



}



